/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package deti.es.ukni.rest;

import deti.es.persistence.calendar.CalendarManagerRemote;
import deti.es.persistence.calendar.EventDoesNotExist;
import deti.es.ukni.cm.persistence.DAOFactory;
import deti.es.ukni.persistence.entity.Event;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;

import org.json.simple.JSONObject;

/**
 * REST Web Service
 *
 * @author eurico
 */

public class BandEventResourceByID {
    @Context
    private UriInfo context;

    /** Creates a new instance of BandResource */
    public BandEventResourceByID() {
    }

    /**
     * Retrieves representation of an instance of deti.es.ukni.rest.BandResource
     * @param name resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    public String getText(@PathParam("id")
    Integer IDEvent) {

        JSONObject json = new JSONObject();

        Event e;
        CalendarManagerRemote CMBean;
        CMBean = DAOFactory.getCalendarManager();
        try {
             e = CMBean.findBandEvent(IDEvent);

        } catch (EventDoesNotExist ex) {
            return json.toJSONString();
        }
        

        json.put("location", e.getLocation());
        json.put("date", e.getEventdate());
        json.put("lat", e.getLatitude());
        json.put("lng", e.getLongitude());

        return json.toJSONString();
    }
}
